//This is a min list, to keep the minimal data for ANN, such as id and distance
//min list don't use malloc, for compliant with embedded processor
//thus all memory that min list used is allocated by caller

#ifndef MIN_LIST_H
#define MIN_LIST_H

//if you want to modify the entry type, you just need to modify the struct minlist_entry, compare_minlist()
typedef struct minlist_entry
{
    int id;
    float distance;
    int flag; //用于标记，例如是否遍历过了
} MINLIST_ENTRY;

typedef struct minlist
{
    int size;               //total count of entries
    int count;              //current count of entries
    int calculate_k;        //用于计算时的k

    struct minlist_entry* entries;  //store entries
} MINLIST;

extern int compare_minlist(struct minlist_entry* A, struct minlist_entry* B); //A>B return 1, otherwise return 0

extern struct minlist* create_minlist(int size); //mem for store struct min_list and entries,
                                                             //you need to allocate sizeof(struct minlist)+size*sizeof(struct minlist_entry)

extern int insert_minlist(struct minlist* list, struct minlist_entry* entry); //insert success return 0, otherwise return 1

extern struct minlist_entry* get_mins(struct minlist* list);       

extern int get_minlist_id(struct minlist* list, int index);

extern void print_minlist(struct minlist* list);

extern void destory_minlist(struct minlist* list);

#endif
